<?
	App::namespace('lib.entity');

	$build = App::get('db_build');
    $name = App::get('db_name');

	// Build database
	if($build)
	{
		$con = new Connection();
		
		$con->query("DROP DATABASE IF EXISTS `$name`")
			->query("CREATE DATABASE `$name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci")
			->db($name);
		
		foreach(scandir('lib/entity') as $file) 
		{				
			if ($file !== '.' && $file !== '..') 
			{						
				$name = substr($file, 0, -4);
				$meta = new EntityMeta($name);
				$sql  = $meta->getSql();
				
				if($sql) $con->query($sql);
			}
		}
		
		$con->close();
	}
?>